package org.vectrics.recruiter.struts.tag;

/**
 * @author Mike Moore
 */
import java.util.Collection;
import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Category;
import org.vectrics.common.db.DataUtils;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.user.CandidateInfo;
import org.vectrics.recruiter.user.Resume;
import org.vectrics.struts.VectricsTagSupport;
import org.vectrics.user.Person;

public class PersonResumeComboTag extends VectricsTagSupport {

	private static final long serialVersionUID = 1598495537038248492L;
	
	static private Category log = Category.getInstance(PersonResumeComboTag.class);
    private String styleClass = null;
    private String property = null;
    private String value = null;
    private String personId = null;
    private String selectedResumeId = null;
    
    
    public PersonResumeComboTag() {
    	super();
    }


	public String makeStartTag() {
		StringBuffer html = new StringBuffer();
		
		log.debug("doStartTag() called");
		HttpServletRequest request = (HttpServletRequest)super.pageContext.getRequest();
		String propValue = request.getParameter(property);
		log.debug("propValue = " + propValue);
		
		//HttpSession session = super.pageContext.getSession();
		if (styleClass == null) {
			html.append("<select name=\"" + this.property 
					+ "\" style=\"width:250;font-family:verdana,arial,sans serif;font-size=" +
							"11px\">");
		}
		else {
			html.append("<select name=\"" + this.property + "\" class=\"" 
					+ styleClass + "\">");
		}
		
		
		Person person = CoreServiceLocator.getPersonService().findPersonById(new Long(personId));
		CandidateInfo candidate = RecruitServiceLocator.getRecruitUserService().findCandidateInfo(person);
		if (candidate != null) {
			Collection resumes = candidate.getResumes();
        	resumes = DataUtils.removeVoided(resumes);
			Iterator iter = RecruitServiceLocator.getJobProvider().findAllJobFunctions().iterator();
			while (iter.hasNext()) {
				Resume resume = (Resume)iter.next();
				String selectStr = "";
				if (resume.getId().toString().equals(this.value)) {
					selectStr = "SELECTED";
				}
				html.append("<option " + selectStr + " value=\"" + resume.getId().toString() + "\">" 
						+ resume.getName()	+ "</option>");
			}
		}
		
		html.append("</select>");

		return(html.toString());
	}


	/**
	 * @return
	 */
	public String getStyleClass() {
		return styleClass;
	}

	/**
	 * @param styleClass
	 */
	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}

	/**
	 * @return
	 */
	public String getProperty() {
		return property;
	}

	/**
	 * @param property
	 */
	public void setProperty(String property) {
		this.property = property;
	}

	/**
	 * @return Returns the value.
	 */
	public String getValue() {
		return value;
	}
	/**
	 * @param value The value to set.
	 */
	public void setValue(String value) {
		this.value = value;
	}
	
	/**
	 * @return Returns the personId.
	 */
	public String getPersonId() {
		return personId;
	}
	/**
	 * @param personId The personId to set.
	 */
	public void setPersonId(String personId) {
		this.personId = personId;
	}
	
	
	/**
	 * @return Returns the selectedResumeId.
	 */
	public String getSelectedResumeId() {
		return selectedResumeId;
	}
	/**
	 * @param selectedResumeId The selectedResumeId to set.
	 */
	public void setSelectedResumeId(String selectedResumeId) {
		this.selectedResumeId = selectedResumeId;
	}
}
